package cn.bas.controller;

import cn.bas.dto.UserAddDTO;
import cn.bas.dto.UserUpdateDTO;
import cn.bas.service.UserService;
import cn.bas.vo.UserVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/users")
public class UserController01 {
    @Resource
    private UserService userService;

    @GetMapping("")
    public List<UserVo> list(){
        List<UserVo> list = new ArrayList<>();
        list.add(new UserVo().setId(1).setUsername("jack"));
        list.add(new UserVo().setId(2).setUsername("mark"));
        list.add(new UserVo().setId(3).setUsername("tom"));
        return list;
    }

    @GetMapping("/{id}")
    public UserVo get(@PathVariable("id") Integer id){
        return new UserVo().setId(id).setUsername("jerry");
    }

    @GetMapping("/v2/{id}")
    public UserVo get2(@PathVariable("id") Integer id){
        System.out.println(userService);
        UserVo uv = userService.get(id);
        return uv;
    }

    @PostMapping("")
    public Integer add(UserAddDTO userAddDTO){
        System.out.println(userAddDTO);
        return  1;
    }

    @PutMapping
    public Boolean update(Integer id, UserUpdateDTO userUpdateDTO){
        userUpdateDTO.setId(id);
        return true;
    }

    @DeleteMapping("/{id}")
    public Boolean deleteById(@PathVariable("id") Integer id){

        return false;
    }

}
